package com.avexVertex.mapper;

import com.avexVertex.pojo.Emp;
import com.avexVertex.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {


    /**
     * 查询总记录数
     *
     * @return
     */
    @Select("select count(*) from emp as e left join dept as d on e.dept_id = d.id")
    public Long count();

    /**
     * 分页查询
     *
     * @return
     */
    @Select("select e.*,d.name from emp as e left join dept as d on e.dept_id = d.id " +
            "order by e.update_time desc limit #{start},#{pageSize}")
    public List<Emp> listOrigin(@Param("start") Integer start, @Param("pageSize") Integer pageSize);

    //    @Select("select e.*,d.name from emp as e left join dept as d on e.dept_id = d.id " +
//            "where e.name like concat('%',#{name},'%') and e.gender=#{gender} and e.entry_date between #{begin} and #{end} "+
//            "order by e.update_time desc")
    public List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);

    public List<Emp> list(EmpQueryParam empQueryParam);


    /**
     * 新增员工
     *
     * @param emp
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /**
     * 根据ID批量删除员工的基本信息
     *
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 根据ID查询员工的基本信息以及工作经历信息
     * @param id
     * @return
     */
    Emp getById(Integer id);

    /**
     * 根据ID更新员工基本信息
     * @param emp
     */
    void updateById(Emp emp);

    /**
     * 统计各职位人的数量
     * @return
     */
    @MapKey("")//此处这个注解只是我欺骗IDEA或MyBatis插件或别的东西，让它不报错
    List<Map<String,Object>> countEmpJobData();

    /**
     * 统计员工性别人数
     * @return
     */
    @MapKey("")//此处这个注解只是我欺骗IDEA或MyBatis插件或别的东西，让它不报错
    List<Map<String, Object>> countEmpGenderData();
}
